<?php

namespace App\Console\Commands;

use App\Models\Fangrent;
use Illuminate\Console\Command;

class FangStatus extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fang:status';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'php artisan fang:status';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //当天日期
        $date=date('Y-m-d');
        //查询所有的租房截止日期为当天的房源
        $data=Fangrent::where('edt',$date)->get();
        foreach ($data as $model){
            // 让已租房源表中的记录变成软删除状态
            $model->delete();
            // 利用 模型关联 关系来进行房源数据状态的修改
            $model->fang->update(['fang_status'=>0]);
        }
        echo "修改完成\n";
    }
}
